package com.example.hp.controller;

import com.example.hp.entity.Enrollments;
import com.example.hp.service.EnrollmentsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Enrollments)表控制层
 *
 * @author makejava
 * @since 2024-12-15 16:49:03
 */
@RestController
@RequestMapping("enrollments")
@Tag(name = "EnrollmentsController", description = "学员的课程报名信息管理接口22001010907 许皓翔")
public class EnrollmentsController {
    /**
     * 服务对象
     */
    @Resource
    private EnrollmentsService enrollmentsService;

    /**
     * 分页查询
     *
     * @param enrollments 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Enrollments>> queryByPage(Enrollments enrollments, PageRequest pageRequest) {
        return ResponseEntity.ok(this.enrollmentsService.queryByPage(enrollments, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Enrollments> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.enrollmentsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param enrollments 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody Enrollments enrollments) {
        return ResponseEntity.ok(this.enrollmentsService.insert(enrollments));
    }

    /**
     * 编辑数据
     *
     * @param enrollments 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Enrollments> edit(@RequestBody Enrollments enrollments) {
        return ResponseEntity.ok(this.enrollmentsService.update(enrollments));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.enrollmentsService.deleteById(id));
    }

}

